﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Habi.Solver.Common;
using Habi.Solver.ViewModels.Meta;
using DevExpress.Utils.MVVM;
using DevExpress.XtraEditors.DXErrorProvider;

namespace Habi.Solver.Views.Meta
{
    public partial class RegsitView : ExtensionControl<RegsitViewModel>
    {
        public RegsitView()
        {
            InitializeComponent();
        }

        public override void InitializeView(MVVMContextFluentAPI<RegsitViewModel> fluent)
        {
            base.InitializeView(fluent);

            fluent.BindCommand(simpleButtonCancel, x => x.Close());

            treeListLookUpEditDepartment.Properties.DisplayMember = "Name";
            treeListLookUpEditDepartment.Properties.ValueMember = "Id";
            treeListLookUpEditDepartment.Properties.TreeList.ParentFieldName = "ParentId";
            treeListLookUpEditDepartment.Properties.TreeList.KeyFieldName = "Id";
            fluent.SetBinding(treeListLookUpEditDepartment.Properties, t => t.DataSource, x => x.Departments);

            fluent.SetBinding(textEditEmail, t => t.Text, x => x.Email);
            fluent.SetBinding(textEditName, t => t.Text, x => x.Name);
            fluent.SetBinding(textEditPassword, t => t.Text, x => x.Password);
            fluent.SetBinding(textEditPassword2, t => t.Text, x => x.Password2);
            fluent.SetBinding(textEditPhone, t => t.Text, x => x.PhoneNumber);

            fluent.SetBinding(treeListLookUpEditDepartment, t => t.EditValue, x => x.DepartmentId);

            fluent.BindCommand(simpleButtonRegist, x => x.Regist());

            ValidationService.SetRules(textEditEmail, new ConditionValidationRule { ConditionOperator = ConditionOperator.IsNotBlank, ErrorText = "E-mail is require ." });
            ValidationService.SetRules(textEditName, new ConditionValidationRule { ConditionOperator = ConditionOperator.IsNotBlank, ErrorText = "Name is require ." });
            ValidationService.SetRules(textEditPassword, new ConditionValidationRule { ConditionOperator = ConditionOperator.IsNotBlank, ErrorText = "Password is require ." });
            ValidationService.SetRules(textEditPassword2, new ConditionValidationRule { ConditionOperator = ConditionOperator.IsNotBlank, ErrorText = "Two password is not compared ." });
            ValidationService.SetRules(textEditPhone, new ConditionValidationRule { ConditionOperator = ConditionOperator.IsNotBlank, ErrorText = "Phone number is require ." });
        }
    }
}
